package com.proj.springbootdemo.config.db;

import com.proj.springbootdemo.utils.ProjectUtils;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liujia
 */
@Configuration
@AutoConfigureAfter(DruidDbConfig.class)
public class MyBatisScannerConfig {
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer conf = new MapperScannerConfigurer();
        conf.setSqlSessionFactoryBeanName("sqlSessionFactory");
        String basePackage = ProjectUtils.basePackage();
        StringBuilder mapperLocations = new StringBuilder();
        mapperLocations.append(basePackage + ".dao.mapper.gen" + ",");
        mapperLocations.append(basePackage + ".dao.mapper");
        conf.setBasePackage(mapperLocations.toString());
        return conf;
    }
}
